package com.lcf.system.controller;


import com.lcf.framework.vo.PageVO;
import com.lcf.system.dto.GoodsDTO;
import com.lcf.system.query.GoodsPageQuery;
import com.lcf.system.service.GoodsService;
import com.lcf.system.vo.GoodsVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 商品(Goods)表控制层
 *
 * @author lcf
 * @since 2025-05-02 11:54:59
 */
@Tag(name = "商品")
@RestController
@RequestMapping("goods")
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    /**
     * 新增
     */
    @Operation(summary = "新增")
    @PostMapping("add")
    public boolean addGoods(@RequestBody @Validated GoodsDTO dto) {
        return goodsService.addGoods(dto);
    }

    /**
     * 删除
     */
    @Operation(summary = "删除")
    @DeleteMapping("{id}")
    public boolean deleteGoods(@PathVariable @Schema(description = "主键") long id) {
        return goodsService.deleteGoods(id);
    }

    /**
     * 修改
     */
    @Operation(summary = "修改")
    @PutMapping("{id}")
    public boolean updateGoods(@PathVariable @Schema(description = "主键") long id,
                               @RequestBody @Validated GoodsDTO dto) {
        return goodsService.updateGoods(id, dto);
    }

    /**
     * 根据id查询
     */
    @Operation(summary = "根据id查询")
    @GetMapping("{id}")
    public GoodsVO getGoods(@PathVariable @Schema(description = "主键") long id) {
        return goodsService.getGoods(id);
    }

    /**
     * 分页查询
     */
    @Operation(summary = "分页查询")
    @GetMapping("page")
    public PageVO<GoodsVO> getGoodsList(GoodsPageQuery query) {
        return goodsService.getGoodsList(query);
    }
}

